<?php
/**
 * Created by PhpStorm.
 * User: huangj11
 * Date: 2021/1/14
 * Time: 19:33
 */

namespace business\elasticsearch\models;


use yii\elasticsearch\ActiveRecord;

class SupplierWordsModel extends ActiveRecord
{

    public function attributes()
    {
        return [
            'uid',
            'word',
            'type',
            'indexCreatedTime',
        ];
    }


    /**
     * @desc 查询
     * @param array $query
     * @return array|ActiveRecord|null
     */
    public static function getOne($query = [])
    {
        $es_query = self::find();

        // 匹配查询
        if ($query && !empty($query)) {
            $es_query->query($query);
        }
        // 分组
        return $es_query->one();
    }

    /**
     * 通过供应商id查询一条信息
     * @param $supplierId
     * @return array|ActiveRecord|null
     */
    public static function getOneBySupplierId($supplierId)
    {
        return self::getOne([
            'term' => [
                'supplierId.keyword' => $supplierId
            ]
        ]);
    }

    public static function index()
    {
        return 'supplier_words';
    }

    public static function type()
    {
        return 'words';
    }
}
